import axios from './index'
import { NowPlaying, Cinema, ComingSoon, FilmInfo, City, CinemaInfo, CinemaFilms, FilmSchedules, Register, Login } from './api'

export function nowPlaying(page, city) {
    return axios('/api' + NowPlaying + '?cityId=' + city + '&pageNum=' + page).then(res => {
        return new Promise((resolve => resolve(res.data)));
    })
}

export function comingSoon(page, city) {
    return axios('/api' + ComingSoon + '?cityId=' + city + '&pageNum=' + page).then(res => {
        return new Promise((resolve => resolve(res.data)));
    })
}

export function cinema(page, city) {
    return axios('/api' + Cinema + '?cityId=' + city + '&pageNum=' + page).then(res => {
        return new Promise((resolve => resolve(res.data)));
    })
}

export function filmInfo(id) {
    return axios('/api' + FilmInfo + '?filmId=' + id).then(res => {
        return new Promise((resolve => resolve(res.data.film)));
    })
}

export function city() {
    return axios('/api' + City).then(res => {
        return new Promise((resolve => resolve(res.data.cities)));
    })
}

export function cinemaInfo(id) {
    return axios('/api' + CinemaInfo + '?cinemaId=' + id).then(res => {
        return new Promise((resolve => resolve(res.data.cinema)));
    })
}

export function cinemaFilms(id) {
    return axios('/api' + CinemaFilms + '?cinemaId=' + id).then(res => {
        return new Promise((resolve => resolve(res.data.films)));
    })
}

export function filmSchedules(cinemaId, filmId) {
    return axios('/api' + FilmSchedules + '?cinemaId=' + cinemaId + '&filmId=' + filmId).then(res => {
        return new Promise((resolve => resolve(res.data.schedules)));
    })
}

// 注册
export function register(data) {
    return axios({
        url: '/admin' + Register,
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data
    })
}

//登录
export function login(data) {
    console.log(data, 222);
    return axios({
        url: '/admin' + Login,
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data
    })
}

